續上篇,今天在 firefox 官網看到幾個過去沒用過,但有點興趣的內容
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
執行時一旦碰到 debugger
這個 statement ,就會啟動debugger。
聽起來很像廢話,但小白如我,只有用過在瀏覽器中找到resource裡面的 JS,雙擊標示breakpoint的這個用法。
這邊用個小程式在不同環境試試看效果,但還是Chrome最深得我心 XD
Safari
Chrome
VSCode
Class 是 ES6 才推出的,讓 JS 可以像 C++、Java 一樣,做物件導向的程式設計
OOP 常見的 keyword,如:super, extends, static, private等等也和其他語言相同
這邊就自己寫個小東西玩玩看
class Vehicle {
constructor(type, year) {
this.type = type;
this.year = year;
}
showInfo() {};
olderThan(anotherVehicle) {
return this.year < anotherVehicle.year;
}
}
class Car extends Vehicle {
constructor(year, licenseNumber) {
super("car", year);
this.licenseNumber = licenseNumber;
}
showInfo() {
console.log(`This is a ${this.type} of ${this.year} with license number ${this.licenseNumber}.`)
}
};
class Bicycle extends Vehicle {
constructor(year, color) {
super("bicycle", year);
this.color = color;
}
showInfo() {
console.log(`This is a ${this.type} of ${this.year} with ${this.color} color.`)
}
}
var car = new Car("2020", "ABC-0123");
car.showInfo();
var bicycle = new Bicycle("2023", "light green");
bicycle.showInfo();
console.log(`Is car older than bicycle? ${car.olderThan(bicycle)}.`)